'    Copyright 2008 Jan Molnar <jan.molnar@abds.de>
'
'    This file is part of JCQ.

'    JCQ is free software: you can redistribute it and/or modify
'    it under the terms of the GNU General Public License as published by
'    the Free Software Foundation, either version 2 of the License, or
'    (at your option) any later version.

'    JCQ is distributed in the hope that it will be useful,
'    but WITHOUT ANY WARRANTY; without even the implied warranty of
'    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'    GNU General Public License for more details.

'    You should have received a copy of the GNU General Public License
'    along with JCQ. If not, see <http://www.gnu.org/licenses/>.

Public MustInherit Class BaseStorageItem
    Implements Interfaces.IStorageItem, System.ComponentModel.INotifyPropertyChanged

    Private ReadOnly _Attributes As System.Collections.Hashtable
    Private _Identifier As String
    Private _Name As String

    Public Sub New()
        _Attributes = New System.Collections.Hashtable
    End Sub

    Public Sub New(ByVal id As String, ByVal name As String)
        _Attributes = New System.Collections.Hashtable
        _Identifier = id
        _Name = name
    End Sub

    Public ReadOnly Property Attributes() As System.Collections.Hashtable Implements Interfaces.IStorageItem.Attributes
        Get
            Return _Attributes
        End Get
    End Property

    Public Property Identifier() As String Implements Interfaces.IStorageItem.Identifier
        Get
            Return _Identifier
        End Get
        Set(ByVal value As String)
            _Identifier = value
            OnPropertyChanged("Identifier")
        End Set
    End Property

    Public Property Name() As String Implements Interfaces.IStorageItem.Name
        Get
            Return If(String.IsNullOrEmpty(_Name), _Identifier, _Name)
        End Get
        Set(ByVal value As String)
            _Name = value
            OnPropertyChanged("Name")
        End Set
    End Property

    Protected Sub OnPropertyChanged(ByVal propertyName As String)
        RaiseEvent PropertyChanged(Me, New System.ComponentModel.PropertyChangedEventArgs(propertyName))
    End Sub

    Public Event PropertyChanged(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
End Class